package com.dcd.controller;

import com.dcd.pojo.Follow_car_series;
import com.dcd.service.Follow_car_seriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Follow_car_seriesController {

    @Autowired
    private Follow_car_seriesService follow_car_seriesService;

    /**
     * 关注指定车系/删除指定用户关注的车系
     *
     * @param follow_car_series 关注车系对象
     * @param type              insert/delete
     * @return
     */
    @RequestMapping("/insert_or_delete_follow_car_series")
    public String insert_or_delete_follow_car_series(@RequestBody Follow_car_series follow_car_series, @RequestParam String type) {
        if (type.equals("insert"))
            return "{\"result\":\"" + follow_car_seriesService.insert_follow_car_series(follow_car_series) + "\"}";
        return "{\"result\":\"" + follow_car_seriesService.delete_follow_car_series(follow_car_series) + "\"}";
    }

    /**
     * 查询用户是否关注指定车系
     *
     * @param follow_car_series
     * @return
     */
    @RequestMapping("/select_user_whether_follow_car_series")
    public String select_user_whether_follow_car_series(@RequestBody Follow_car_series follow_car_series) {
        return "{\"result\":\"" + follow_car_seriesService.select_user_whether_follow_car_series(follow_car_series) + "\"}";
    }

    /**
     * 根据用户登录的id查询所有关注的车系
     * @param user_id 登录的用户id
     * @return
     */
    @RequestMapping("/select_follow_car_series")
    public List<Follow_car_series> select_follow_car_series(@RequestParam int user_id){
        return follow_car_seriesService.select_follow_car_series(user_id);
    }
}
